package com.centaline.androidsalesblog.widgets.dropdown;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ListView;

import com.centaline.androidsalesblog.R;
import com.centaline.androidsalesblog.model.businissobject.DropBo;

import java.util.ArrayList;

/**
 * 单列
 * Created by guilin on 16/1/13.
 */
public class SingleDrop extends AbsDrop {

    private FrameLayout fl_parent;
    private ListView listView;
    private DropTextAdapter dropTextAdapter;

    public SingleDrop(View anchor, Context context) {
        super(anchor, context);
        View view = LayoutInflater.from(context).inflate(R.layout.layout_drop_single, null);
        fl_parent = (FrameLayout) view.findViewById(R.id.fl_parent);
        fl_parent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        listView = (ListView) view.findViewById(R.id.listView);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                dropTextAdapter.select(position);
                dropComplete(false, arrayList.get(position).getType(), arrayList.get(position));
            }
        });
        dropTextAdapter = new DropTextAdapter(arrayList);
        listView.setAdapter(dropTextAdapter);
        initPopWindow(view);
    }

    @Override
    public void init(ArrayList<DropBo> dropBos) {
        arrayList.clear();
        arrayList.addAll(dropBos);
        dropTextAdapter.notifyDataSetChanged();
    }

    @Override
    public void onDismiss() {
    }
}
